﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Customer.Bussiness_Service;
using Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ServiceCore;
using static ServiceCore.Tool.ES.es_cloud_product;

namespace Customer.Areas.Cloud_Product.Controllers
{
    [ApiController, Area("cloud_product"), Route("/cloud_product/[action]")]
    public class cloud_productController : ControllerBase
    { 
        private readonly Icloud_product_service _service;
        private readonly IToole_DI _tool;
        public cloud_productController(Icloud_product_service service, IToole_DI tool)
        {
            _service = service;
            _tool = tool;
        }
        /// <summary>
        /// 添加云商品库
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultObjModel save_cloud(cloud_product Params)
        {
            var result = _service.save_cloud_product(Params);
            return result;
        }  
        /// <summary>
        /// 从云商品库clone商品到本地商品库
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel clone_customer(string id)
        {
            var result = _service.clone_customer_product(id);
            return result;
        } 
        /// <summary>
        /// 搜索云商品库数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultObjModel get_cloud_list(cloud_product_search Params)
        {
            var result = _service.get_cloud_product_list(Params);
            return result;
        } 
        /// <summary>
        /// 检测codebar在云商品库里是否存在数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_codebar_product(string codebar)
        {
            var result = _service.get_codebar_product(codebar);
            return result;
        }

        /// <summary>
        /// 获取商品分类
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_cate_list()
        {
            var result = _service.get_cate_list();
            return result;
        }

        /// <summary>
        /// 获取模板信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_structure_template(string name)
        {
            var result = _service.get_structure_template(name);
            return result;
        }

        /// <summary>
        /// 获取模板信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPatch]
        public async Task<ResultObjModel> start_synchronization_rk_stock()
        {
            var result = await _service.start_synchronization_rk_stock();
            return result;
        }

        /// <summary>
        /// 搜索云商品库数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel del_cloud(string id)
        {
            var result = _service.del_cloud_product(id);
            return result;
        }
    }
}